;(function(){
	var of = 0;
	var num = 10;
	var token = $.cookie('token');
	$(document).ready(function(){
		$(".buit").click(function(){
			$(".weather-top").fadeIn();
			$(".weather-mid").fadeIn();
		})
		$(".close").click(function(){
			$(".weather-top").fadeOut();
			$(".weather-mid").fadeOut();
		})
		$("#exit").click(function(){
			window.location.href ="login.html";
		})
		$(".active").fadeIn(function(){
			var a = $("#dt .active #area").html();
			var b = $("#dt .active #area2").html();
			$.ajax({
				url:'/WebService1.asmx/GetWeather',
				type:'post',
				headers:{'Content-Type':'application/x-www-form-urlencoded',},
				data:{token:token,area:a,area2:b,offset:of,number:num},
				dataType:"text",
				success:function(data){
					dat = data.replace(/\s*/g,"");
					console.log(dat);
					var parser=new DOMParser(); 
					var x = $('<div/>').html(dat).text();
					var xmlDoc=parser.parseFromString(x,"text/xml"); 
					console.log(xmlDoc);
					var xNode=xmlDoc.getElementsByTagName("NewDataSet")[0].childNodes;
					console.log(xNode);
					var str="<tr><td>序号</td><td>日期</td><td>天气一</td><td>天气二</td></tr>";
					for (i = 0; i <xNode.length; i++) {
					var dd = xNode[i];
					var id =  i+1;
					var time =  dd.getElementsByTagName("expire")[0].firstChild.nodeValue.slice(0,10);
					var param =  dd.getElementsByTagName("param")
					if (param.length > 0 && param[0].firstChild) {
						param =  param[0].firstChild.nodeValue;
					}else{
						param = "无天气数据"
					}
					var param2 =  dd.getElementsByTagName("param2")
					if (param2.length > 0 && param2[0].firstChild) {
						param2 =  param2[0].firstChild.nodeValue;
					}else{
						param2 = "无天气数据"
					}
					str+='<tr><td>'+id+'</td><td>'+time+'</td><td>'+param+'</td><td>'+param2+'</td></tr>';
						}
					$("#tabletest").html('<tr>'+str+'</tr>');
				},
			})
		});
		$("#dt li").click(function(){
			$("#dt .active").removeClass("active");
			$(this).addClass("active");
			var a = $("#dt .active #area").html();
			var b = $("#dt .active #area2").html();
			$.ajax({
				url:'/WebService1.asmx/GetWeather',
				type:'post',
				headers:{'Content-Type':'application/x-www-form-urlencoded',},
				data:{token:token,area:a,area2:b,offset:of,number:num},
				dataType:"text",
				success:function(data){
					dat = data.replace(/\s*/g,"");
					// console.log(dat);
					var parser=new DOMParser(); 
					var x = $('<div/>').html(dat).text();
					var xmlDoc=parser.parseFromString(x,"text/xml"); 
					// console.log(xmlDoc);
					var xNode=xmlDoc.getElementsByTagName("NewDataSet")[0].childNodes;
					// console.log(xNode);
					var str="<tr><td>序号</td><td>日期</td><td>天气一</td><td>天气二</td></tr>";
					for (i = 0; i <xNode.length; i++) {
					var dd = xNode[i];

					var id =  i+1;
					var time =  dd.getElementsByTagName("expire")[0].firstChild.nodeValue.slice(0,10);
					var param =  dd.getElementsByTagName("param")
					if (param.length > 0 && param[0].firstChild) {
						param =  param[0].firstChild.nodeValue;
					}else{
						param = "无天气数据"
					}
					var param2 =  dd.getElementsByTagName("param2")
					if (param2.length > 0 && param2[0].firstChild) {
						param2 =  param2[0].firstChild.nodeValue;
					}else{
						param2 = "无天气数据"
					}
					str+='<tr><td>'+id+'</td><td>'+time+'</td><td>'+param+'</td><td>'+param2+'</td></tr>';
						}
					$("#tabletest").html('<tr>'+str+'</tr>');
				},
			})
		});
	})
}());